/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aviso.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

/**
 *
 * @author avgusti
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "Area.lookUp", query = "select a from Area a where lower(a.name) LIKE :query"),
    @NamedQuery(name = "Area.lookUpByType", query = "select a from Area a where a.type.id=:typeid and lower(a.name)  LIKE :query"),
    @NamedQuery(name = "Area.getByName", query = "select a from Area a where a.name=:query"),
    @NamedQuery(name="Area.listByFirstParentID", query = "select a from Area a where a.parent.id=:parentid")    
})
public class Area extends GeoTag implements Serializable {

    private static final long serialVersionUID = 1L;
    @ManyToOne
    private Area parent;
    @ManyToOne
    private AreaType type;
    @OneToMany(cascade = CascadeType.REMOVE, orphanRemoval = true)
    private List<Area> children=new ArrayList<Area>();

    public List<Area> getChildren() {
        return children;
    }

    public void setChildren(List<Area> children) {
        this.children = children;
    }

    public Area getParent() {
        return parent;
    }

    public void setParent(Area parent) {
        this.parent = parent;
    }

    public AreaType getType() {
        return type;
    }

    public void setType(AreaType type) {
        this.type = type;
    }
    

    @Override
    public String toString() {
        return getName();
    }
}
